package shplate

class MakeReportOneStepController {

    def dynamicQueryService

    def makeReportOneStep() {
        def pageCurrent = params.pageCurrent ? Integer.parseInt(params.pageCurrent) : 1
        def pageSize = params.pageSize ? Integer.parseInt(params.pageSize) : 10
        params.startno = (pageSize * (pageCurrent - 1)) + 1
        params.endno = pageSize * pageCurrent
        def pageSizeList = [10, 20, 50, 100]
        params.SYS_QUERY_NAME = 'makeReportOneStep'
        def makeReportOneStep = dynamicQueryService.queryForList(params)
        def tableHeadList = []
        if (makeReportOneStep.size() > 0) {
            tableHeadList = makeReportOneStep[0].keySet()
        }
        params.SYS_QUERY_NAME = 'makeReportOneStepChart'
        def makeReportOneStepChart = dynamicQueryService.queryForList(params)
        [
                tableHeadList         : tableHeadList,
                pageSizeList          : pageSizeList,
                pageSize              : pageSize,
                startno               : params.startno ?: '',
                endno                 : params.endno ?: '',
                startTime             : params.startTime ?: '',
                endTime               : params.endTime ?: '',
                makeReportOneStep     : makeReportOneStep,
                makeReportOneStepChart: makeReportOneStepChart
        ]
    }

    def exportExcel() {
        params.startno = 1
        params.endno = 99999999999999999
        params.SYS_QUERY_NAME = 'makeReportOneStep'
        def makeReportOneStep = dynamicQueryService.queryForList(params)
        def tableHeadList = []
        if (makeReportOneStep.size() > 0) {
            tableHeadList = makeReportOneStep[0].keySet()
        }
        String filename = new String("makeReportOneStep.xls".getBytes("UTF-8"), "UTF-8");
        response.setContentType('application/vnd.ms-excel;charset=UTF-8')
        response.setHeader('Content-disposition', "attachment;filename=${filename};charset=UTF-8")
        response.setCharacterEncoding("UTF-8");
        render(template: "export${params.EXPORT_CONTENT_NAME}", model: [makeReportOneStep: makeReportOneStep, tableHeadList: tableHeadList])
    }
}